﻿/**
   Данный объект представляет из себя радиосвзь между водолазами.
   В данном объекте хрянятся сопоставления о найденных звездах
 */

(function () {
    "use strict";

    F.RadioCommunications = function () {
        var self = this;
        self.seenStars = {};
    };

    var rcp = F.RadioCommunications.prototype;

    rcp.isStarBusy = function (star, aqualunger) {
        var self = this;
        return !!self.seenStars[star];
    };

    rcp.setStarAsBusy = function (star, aqualunger) {
        var self = this;
        if (self.isStarBusy(star, aqualunger))
            throw "Logical error. You can not re-establish the star as busy.";
        self.seenStars[star] = aqualunger;
    };

    rcp.setStarAsFree = function (star, aqualunger) {
        var self = this;
        if (!self.isStarBusy(star, aqualunger))
            throw "Logical error. You can not release the star that was not occupied.";
        if (self.seenStars[star] !== aqualunger)
            throw "Logical error. Star can release only diver to capture it.";
        delete self.seenStars[star];
    };

    rcp.setStarAsCollected = function (star, aqualunger) {
        var self = this;
        self.setStarAsFree(star, aqualunger);
    };

    rcp = null;

} ());